<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" type="text/css" href="../themes/general.css">
	<link rel="stylesheet" type="text/css" href="../themes/icon.css">
	<link rel="stylesheet" type="text/css" href="../themes/gray/easyui.css">
	<script type="text/javascript" src="../scripts/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" src="../scripts/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../scripts/locale/easyui-lang-zh_CN.js"></script>
	<title>Main</title>
	<script>
	
	
		$(function(){
			$.getJSON("../ana/getCurrentMenus.ajax", function(data){ 
            	init_menu(data);
            });
            
            $.getJSON("../ana/getCurrentUserName.ajax", function(data){
	            $("#cur_user").text(data.username); 
	            $("#cur_userId").val(data.userId); 
            });
            
            $.ajax({
        		url : '../ana/checkCheckPermission.ajax',
        		type : 'post',
        		dataType : 'JSON',
        		cache: false,
        		error: function(XMLHttpRequest, textStatus, errorThrown) {
                            //alert(XMLHttpRequest.status);
                },
        		success : function(data) {
					if(data.success){
					}
        		}
        	}); 
		});
		
		function init_menu(menu_data) {
			$("#menu_container").empty();
		    for(var i=0; i<menu_data.menus.length; i++) {
		        var n = menu_data.menus[i];
		        
		        var sub_menu_str = "";
		        
		        for (var j=0;j<n.submenus.length; j++){
			    	var o = n.submenus[j];
			    	sub_menu_str += "<div style=\"padding:0px;background:#fafafa;overflow:hidden\"><a href=\"javascript:void(0)\" class=\"easyui-linkbutton\"  plain=\"true\" iconCls=\"icon-menu-" + o.code + "\" style=\"width:100%;\" onclick=\"addTabWithIcon('" + o.name + "','" + ".." + o.url +"','icon-menu-" + o.code +"')\">"+o.name+"</a></div>";   	
			    }
		        
		        $('#menu_container').accordion('add', {
			        title: n.name,
			        content: sub_menu_str,
			        selected: false
			    })
		    }
		    
		    $("#menu_container").accordion("select", 0);
		}
		
		function addTabWithIcon(title, href,icon){
			alert(href);
			 if (href){  
		         var content = '<iframe scrolling="auto" frameborder="0"  src="'+href+'" style="width:100%;height:100%;"></iframe>';  
		     } else {  
		         var content = '未实现';  
		     }  
		    var tt = $('#tabs');  	   
		    if (tt.tabs('exists', title)){//如果tab已经存在,则选中该tab，并更新内容          
		        tt.tabs('select', title);  
		        var tab = $('#tabs').tabs('getSelected'); 
		        $('#tabs').tabs('update', {
		        	tab: tab,
		        	options: {
		        		content:content
		        	}
		        });
		    } else {
		    	var tabcount = $('#tabs').tabs('tabs').length;
		    	if (tabcount>10){
			    	$.messager.alert("提示","对不起，最多只能同时打开10个菜单。","info");
			    	return;
			    }
		        tt.tabs('add',{  
		            title:title,  
		            closable:true,  
		            content:content,
		            iconCls:icon||'icon-default'  
		        });  
		    }  
		}
		
		function editTabTitle(title){
		    var tt = $('#tabs');  	   
		    if (tt.tabs('exists', title)){//如果tab已经存在,则选中该tab          
		        tt.tabs('select', title);  
		        var tab = $('#tabs').tabs('getSelected'); 
		        $('#tabs').tabs('update', {
		        	tab: tab,
		        	options: {
		        		title: ""
		        	}
		        });
		    }  
		}
		
		function closeTabByTitle(title){
			var tt = $('#tabs');
			if (tt.tabs('exists', title)){//如果tab已经存在,则选中该tab
		        tt.tabs('close', title);
			}
		}
		
		function go_home() {
			var tt = $('#tabs');  	    	    
		    tt.tabs('select', '主页');
		}
		
		function change_password() {
			$("#dlg_change_password").dialog('open');
		}
		
		function logout() {
			alert("logtou simulation")
			window.location.replace("./login.jsp");
		}
		
		function conformPassword(){
			var password = $('#password').val();
			if(null==password||password==""){
				$.messager.alert('Info', '密码不能为空', 'info');
				return;
			}
			var newPasswd = $('#newPasswd').val();
			var newPasswdConfirm = $('#newPasswdConfirm').val();
			if(null==newPasswd||newPasswd==""){
				$.messager.alert('Info', '新密码不能为空', 'info');
				return false;
			}
			
			if(newPasswd !== newPasswdConfirm){
				$.messager.alert('Info', '两次密码不一致', 'info');
				return false;
			} 
			return true;
		}
		
		function doSubmit(){
			var password = $('#password').val();
			var newPasswd = $('#newPasswd').val();
			var id = $('#cur_userId').val();
			$.ajax({
				url : '../user/changePasswordForLoginUser.ajax?'+new Date().getTime(),
				type : 'get',
				dataType : 'JSON',
				data:{
					password:password,
					newPasswd:newPasswd,
					id:id
				},
				success : function(data) {
					if(data.success){
						alert(data.message);
						$('#password').val('');
						$('#newPasswd').val('');
						$('#newPasswdConfirm').val('');
						$('#dlg_change_password').dialog('close');
					}else{
						alert(data.message);
					}
				}
			});
		}
		
		function init_view_by_permission() {
			$.ajax({
				url : '../ana/checkPermission.ajax',
				type : 'get',
				dataType : 'JSON',
				data : {
					permissionCode : 'CHANGE_LOGINPASSWORD'
				},
				success : function(data) {
					if (data.success) {
						$('#iconPassword').show();
						$('#changePassword').show();
					} else {
						$('#iconPassword').hide();
						$('#changePassword').hide();
					}
				}
			});
		}
		init_view_by_permission();
	</script>
</head>
<body class="easyui-layout" >
	<div data-options="region:'north',border:true" style="height:64px;padding:5px 5px 0px 10px;background:#F9F9F9;">
		<table width="100%">
			<tr>
				<td align="left" valign="bottom"><img src="../images/logo1.png" width="50" height="50"/>&nbsp;&nbsp;<b>监造信息管理系统</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></td>
				<td align="right" valign="bottom">
				 	<input type="text" name="cur_userId" id="cur_userId" style="display:none;"/>
					<span class="icon-user">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>当前用户：<span id="cur_user"></span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<span class="icon-home">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><a href="javascript:void(0)" onclick="go_home()">主页</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<span class="icon-password" id="iconPassword" name="iconPassword">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><a href="javascript:void(0)" onclick="change_password()" id="changePassword" name="changePassword">修改密码</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<span class="icon-logout">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><a href="../ana/logout.do" target="_top">退出</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				</td>
			</tr>
		</table>
	</div>
	<!--
	<div data-options="region:'south',border:false" style="height:40px;padding:10px;background:#ccc;">
		<p>The south content.</p>
	</div>
	-->
	<div data-options="region:'west',split:true" title="菜单导航" style="width:200px;padding:0px;overflow:hidden;">
		<div id="menu_container" class="easyui-accordion" data-options="fit:true,border:false"></div>
		<div id="dlg_change_password" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px" data-options="  
                title: '修改密码',
                closed:true,
                modal:true,  
                buttons: [{  
                    text:'确认',  
                    iconCls:'icon-ok',  
                    handler:function(){  
                    	if(conformPassword()){
                    		doSubmit();
                    	};
                    }  
                },{  
                    text:'取消',  
                    handler:function(){ 
                    	$('#dlg_change_password').dialog('close'); 
                    }  
                }]  
            ">
         <div id="pwd">  
			<table class="table_new" >
					<tr>
						<td class="td_new_name">原密码</td>
						<td class="td_new_value"><input
							class="input_140" type="password" data-options="required:true" id="password" name="password"></td>
					</tr>
					<tr>
						<td class="td_new_name">新密码</td>
						<td class="td_new_value"><input
							class="input_140" type="password"
							data-options="required:true" id="newPasswd" name="newPasswd"></td>
					</tr>
					<tr>
						<td class="td_new_name">确认密码</td>
						<td class="td_new_value">
							<input type="password" class="input_140" data-options="required:true" id="newPasswdConfirm" name="newPasswdConfirm"></td>
					</tr>
			</table>	
		</div>
		</div>
	</div>
	<div id="content_region" data-options="region:'center'" style="overflow-y:hidden;">
		<div id="tabs" class="easyui-tabs" data-options="border:false" fit="true">
			<div title="主页" data-options="closable:false" style="padding:5px;overflow:hidden;"> 
				<p>欢迎使用监造信息管理系统。</p>
			</div>
		</div>
	</div>
	
</body>
</html>